﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Reporting.WebForms;
using Catering.View_Operaction;
using System.IO;
using System.Data;

namespace Catering.Catering_Page.JieGouJianKong
{
    public partial class Xiaohao_cal : System.Web.UI.Page
    {
        private static View_Monitor vm = new View_Monitor();
        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected void lbtnsubmit_Click(object sender, EventArgs e)
        {
            string CLASSID = UCDDLToolWithYearOfMonth1.GetDDL_Class();
            string AREAID = UCDDLToolWithYearOfMonth1.GetDDL_Area();
            DateTime DTIME = UCDDLToolWithYearOfMonth1.GetDateTime();
            string TimeType = UCDDLToolWithYearOfMonth1.GetTimeType();

            if (DTIME.Year.Equals(1949))
            {
                return;
            }
            switch (TimeType)
            {
                case "Year":
                    GetXiaohaoCalByYear(AREAID, CLASSID, DTIME);
                    break;
                case "Month":
                    GetXiaohaoCalByMonth(AREAID, CLASSID, DTIME);
                    break;
            }
        }

        private void GetXiaohaoCalByYear(string AREAID, string CLASSID, DateTime DTIME)
        {
            string Title = Bind_Data_to_Controls.Bind_ReportTitle(AREAID, CLASSID, DTIME, "消耗计算表");
            string pid = "0";
            if (Session["UserID"] != null) pid = Session["UserID"].ToString();
            DataTable dt = vm.GetXiaohao_Cal(pid, AREAID, CLASSID, DTIME.Year.ToString(), Title);
            ReportDataSource rds = new ReportDataSource("DataSet1", dt);
            ReportViewer2.LocalReport.DataSources.Clear();
            ReportViewer2.LocalReport.ReportPath = @"Catering_Page\JieGouJianKong\Report\Xiaohao_cal.rdlc";
            ReportViewer2.LocalReport.DataSources.Add(rds);
            ReportViewer2.LocalReport.Refresh();
            ReportViewer2.Visible = true;
        }

        private void GetXiaohaoCalByMonth(string AREAID, string CLASSID, DateTime DTIME)
        {
            ReportViewer2.LocalReport.DataSources.Clear();
            string Title = Bind_Data_to_Controls.Bind_ReportTitle(AREAID, CLASSID, DTIME, "消耗计算表");
            string pid = "0";
            if (Session["UserID"] != null) pid = Session["UserID"].ToString();
            DataTable dt = vm.GetXiaohao_CalForMonth(pid, AREAID, CLASSID, DTIME, Title);
            ReportDataSource rds = new ReportDataSource("DataSet1", dt);
            ReportViewer2.LocalReport.ReportPath = @"Catering_Page\JieGouJianKong\Report\Xiaohao_calByMonth.rdlc";
            ReportViewer2.LocalReport.EnableExternalImages = true;
            ReportViewer2.LocalReport.DataSources.Add(rds);
            ReportViewer2.LocalReport.Refresh();
            ReportViewer2.Visible = true;
        }
    }
}